﻿Imports System.Data.SqlClient

Public Class Form1
    Private Sub Form1_Load(
          ByVal sender As Object,
          ByVal e As System.EventArgs) _
          Handles Me.Load
        Me.SqlConnection1.ConnectionString =
          "Integrated Security=SSPI;" &
          "Persist Security Info=False;" &
          "User ID='';" &
          "Initial Catalog=NorthWind;" &
          "Data Source=HP;" &
          "Initial File Name=''"
    End Sub

    Private Sub btnLeggiRecord_Click(
          ByVal sender As System.Object,
          ByVal e As System.EventArgs) _
          Handles btnLeggiRecord.Click
        Dim SQL As String = _
         "SELECT * FROM Clienti " & _
         "WHERE ID < '10'"
        Dim riga As String = ""
        Me.SqlConnection1.Open()
        Dim Comando As New SqlCommand(SQL, Me.SqlConnection1)
        Dim dr As SqlDataReader = Comando.ExecuteReader()
        While dr.Read()
            riga = "Cod. " &
               dr("ID").ToString &
               " = " &
               dr("Nome").ToString & "  " &
               dr("Cognome").ToString
            Me.ListBox1.Items.Add(riga)
        End While
        Me.SqlConnection1.Close()
        Me.Label1.Text = "Lettura terminata!"
    End Sub
End Class
